from PyQt5.QtWidgets import QAction, QMenu

from huza.base.mainwindow_run import MainWindowRun
from huza.ribbon.RibbonButton import RibbonButton


def init_after_func(self: MainWindowRun):
    tab_item = self.get_ribbon_tab_item('开始')
    solver_panel = tab_item.add_ribbon_pane('自动添加')
    qaction = QAction(self.icon_list.d1.lightcomponentDTcreateDT71, '新增')

    tb = RibbonButton(self.mainwindow, qaction, True)
    qm = QMenu()
    def add():
        print('add')
    add_action = QAction(self.icon_list.d1.lightcomponentDTcreateDT71, '新增任务', tb)
    add_action.triggered.connect(add)

    qm_tasks = QMenu(tb)
    qm_tasks.setTitle('查看任务')
    qm_tasks.setIcon(self.icon_list.d1.lightcomponentautomationselectItem135)
    task_action = QAction(self.icon_list.d1.lightcomponentautomationselectItem135, 'test1', qm_tasks)
    qm_tasks.addAction(task_action)

    task_action1 = QAction(self.icon_list.d1.lightcomponentautomationselectItem135, 'test2', qm_tasks)
    qm_tasks.addAction(task_action1)

    qm.addAction(add_action)
    qm.addMenu(qm_tasks)
    tb.setPopupMode(2)
    tb.setMenu(qm)


    solver_panel.add_ribbon_widget(tb)
